package cn.com.fssg.platform.base.handler;

import lombok.Data;

import java.util.Map;

/**
 * form自定义操作处理器接口
 * @author kinta
 */
public interface FormHandler {

    /**
     * form保存前
     * @return
     */
    boolean beforeSave(String formCode, String keyName, String keyValue, FormData formData) throws Exception;

    /**
     * form保存后
     * @return
     */
    boolean afterSave(String formCode, String keyName, String keyValue, FormData formData) throws Exception;

    /**
     * form初始化后
     * @return
     */
    boolean afterInit(String formCode, String keyName, String keyValue, FormData formData) throws Exception;

    /**
     * 允许初始化后修改主表数据dataRow，修改后要把dataRow返回
     * @param formCode
     * @param keyName
     * @param keyValue
     * @param formData
     * @param dataRow
     * @return
     */
    Map<String, Object> afterInit(String formCode, String keyName, String keyValue, FormData formData,Map<String, Object> dataRow) throws Exception;

    /**
     * form删除后
     * @return
     */
    boolean afterDelete(String formCode, String keyName, String keyValue, FormData formData) throws Exception;


    @Data
    public class FormData{
        private Map<String, Object> main;
        private Map<String,Object> sub;

        public FormData() {}

        public FormData(Map<String, Object> main, Map<String,Object> sub) {
            this.main = main;
            this.sub = sub;
        }
    }
}
